#include "carina/common/patterns.hh"
#include "carina/common/logging.hh"

#include <cstdlib>

void _TestCaseFunction();

namespace Carina
{
int TestingEnvironment(const char* desc)
{
    try
    {
        Log::stream(Carina::CE_LOG_INFO) << "TEST: " << desc << std::endl;
        _TestCaseFunction();
    }
    catch(const Exception& e)
    {
        Log::stream(Carina::CE_LOG_ERROR) << "FAILURE: Carina exception captured:\n\t" << e.what() << std::endl;
        return EXIT_FAILURE;
    }
    catch(const std::exception& e)
    {
        Log::stream(Carina::CE_LOG_ERROR) << "FAILURE: Standard exception captured:\n\t" << e.what() << std::endl;
        return EXIT_FAILURE;
    } 
    catch(...)
    {
        Log::stream(Carina::CE_LOG_ERROR) << "FAILURE: Unknown exception captured:\n\t" << std::endl;
        return EXIT_FAILURE;
    }
    Log::message(Carina::CE_LOG_INFO, "SUCCESSFULLY COMPLETED!");\
    return EXIT_SUCCESS;
}
}

#define CE_TEST(desc) \
    int CarinaMain(int argc, char** argv) {\
        return Carina::TestingEnvironment(desc); \
    } \
    void _TestCaseFunction()
